#==============================================================================
#  _   _                         ____                _             
# | | | | ___  _ __ ___   ___   / ___|___  _ __ ___ (_)_ __   __ _ 
# | |_| |/ _ \| '_ ` _ \ / _ \ | |   / _ \| '_ ` _ \| | '_ \ / _` |
# |  _  | (_) | | | | | |  __/ | |__| (_) | | | | | | | | | | (_| |
# |_| |_|\___/|_| |_| |_|\___|  \____\___/|_| |_| |_|_|_| |_|\__, |
#                                                            |___/ 
#------------------------------------------------------------------------------
# Project:	Home Coming / 2D platform
# Author:	zx.longgi
# Time:		08/10-2010 
# Usage:	file operator for *.concrete
# Description:	functions for operating concrete filetype
# ClassName:	zfile_concrete
#==============================================================================

from zfile import zfile

class zfile_concrete(zfile):
	"""file operator for *.concrete"""
	nlines = []
	map_property_list = []
	static_object_list = []
	block_list = []

	def __init__(self, filename):
		self.open_and_prepare_concrete_file(filename)
	
	
	def open_and_prepare_concrete_file(self, filename):
		#read all lines into a list
		lines = self.open_read_and_close(filename)
		
		#delete unneeded lines
		for line in lines:
			#delete all lines that start with //
			if(line.strip() == ""):
				continue
			if(self.check_line_is_comment_or_not(line)):
				continue
			if(self.check_line_is_section_name(line)):
				continue
			
			self.nlines.append(line)
			print line
			
			#categorize 
			self.categorize_line(line)
	
	def categorize_line(self, cline):
		"""categorize each line, for further usage"""
		temp_list = cline.strip().split()
		
		#situation 1: map property
		if(temp_list[0].lower() == "map" and len(temp_list) == 3):
			#delete first value
			del temp_list[0]
			#add to map list
			self.map_property_list.add(temp_list)
			return 1
			
		#situation 2: static object
		if(temp_list[0].lower() == "sobj" and len(temp_list) == 12):
			#delete first 2 values
			del temp_list[0]
			#add to static object list
			self.static_object_list.add(temp_list)
			return 2
			
		#situation 3: block
		if(temp_list[0].lower() == "block" and len(temp_list) == 4):
			#delete first value
			del temp_list[0]
			#add to static object list
			self.block_list.add(temp_list)
			return 3